﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class GetActivityMemberListAction : GetAction<Params.GetActivityMemberListParams,
        Results.GetActivityMemberListResult>
    {
        protected override ActionResult<Results.GetActivityMemberListResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            Params.GetActivityMemberListParams opParams)
        {
            ServiceResult<List<Model.Data.ActivityMember>> serviceResult = new ActivityService().GetMemberList(opParams.ActivityId);

            Results.GetActivityMemberListResult actionResult = new Results.GetActivityMemberListResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                for (int index = 0; index < serviceResult.Data.Count; index++)
                {
                    Results.GetActivityMemberListResult.MemberItem item = new Results.GetActivityMemberListResult.MemberItem();
                    item.Id = serviceResult.Data[index].Id;
                    item.NickName = serviceResult.Data[index].NickName;
                    item.AvatarUrl = string.Format("{0}{1}", Configs.BaseWebUrl, serviceResult.Data[index].AvatarUrl); ;
                    item.Type = serviceResult.Data[index].Type;
                    item.JoinTime = serviceResult.Data[index].JoinTime;
                    item.Sex = serviceResult.Data[index].Sex;
                    item.City = serviceResult.Data[index].City;

                    actionResult.Add(item);
                }
                return new ActionResult<Results.GetActivityMemberListResult>("1.0.1", true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.GetActivityMemberListResult>("1.0.1", false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
